<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>平移</title>
</head>
<body>

<script>
    function draw() {


        var c=document.getElementById("myCanvas");
        var ctx=c.getContext("2d");
        ctx.fillStyle="green"
        ctx.fillRect(0,0,100,25);
        ctx.translate(200,100)}
</script>

<canvas id="myCanvas" width="600" height="400" style="border:1px solid #74d359;">
</canvas>
<p><button type="button" onclick="draw();">绘图</button></p>
</body>
</html>